const readline = require('readline-sync');
let arr = [{
        name: "zhangsan",
        password: '123'
    },
    {
        password: '456',
        name: "lisi",
    }
];
// 登录
function login() {
    console.log("请输入账号：");
    let iptId = readline.question();
    console.log("请输入密码：");
    let iptPwd = readline.question();

    // result : [] [{}]
    // let result = arr.filter(function (item) {
    //     return iptId == item.name && iptPwd == item.password
    // });

    // result: [][{}]
    let result = arr.filter(item => iptId == item.name && iptPwd == item.password);
    if (result.length) {

    }

    // result: un   {}
    // let result = arr.filter(item => iptId == item.name && iptPwd == item.password)[0];

    // if (result) {

    // }else{

    // }


    // let flag = false;
    // for (let i = 0; i < arr.length; i++) {
    //     if (arr[i].name == iptId && arr[i].password == iptPwd) {
    //         flag = true;
    //         break;
    //     }
    // }
    // if (flag) {
    //     console.log("成功");
    // } else {
    //     console.log("失败");
    // }
}
// login();

// 注册
function register() {
    console.log("请输入账号：");
    // let iptId = readline.question();
    let name = readline.question();
    let result = arr.some(item => name == item.name);

    if (result) { // 查找到一样的账号
        console.log("账号已被占用");
    } else {
        console.log("请输入密码：");
        let password = readline.question();
        // arr.push({
        //     name: name,
        //     password: password
        // });
        arr.push({
            name,
            password
        });
    }
}
// register();

let obj = {
    name: "zhangsan",
    talk: function () {
        console.log(`${obj.name}`);
    }
}
// obj.talk();
